package com.android.happymall.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;

/**
 * Created by Administrator on 2017/8/31.
 */

public class RY_Scrollview extends ScrollView{
    private float mDownPosX = 0;
    private float mDownPosY = 0;

                public RY_Scrollview(Context context) {
                super(context);
            }

                public RY_Scrollview(Context context, AttributeSet attrs) {
              super(context, attrs);
            }
                public RY_Scrollview(Context context, AttributeSet attrs, int defStyleAttr) {
             super(context, attrs, defStyleAttr);

         }


               @Override
       public boolean onInterceptTouchEvent(MotionEvent e) {
                int action = e.getAction();
                   final float x = e.getX();
                   final float y = e.getY();
                switch (action) {
                        case MotionEvent.ACTION_DOWN:
                            mDownPosX = x;
                            mDownPosY = y;
                              break;
                        case MotionEvent.ACTION_MOVE:
                            final float deltaX = Math.abs(x - mDownPosX);
                            final float deltaY = Math.abs(y - mDownPosY);
                            // 这里是否拦截的判断依据是左右滑动，读者可根据自己的逻辑进行是否拦截
                              // return  false;
                            if (deltaX > deltaY) {// 左右滑动不拦截
                                return false;
                            }
//                            else
//                            {
//                                return  true;
//                            }
                       }
              return super.onInterceptTouchEvent(e);
            }

}
